﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;
using FU.Capstones.IMS.Web.Silverlight.Models;
using FU.Capstones.IMS.Web.Silverlight.Popups;
using Microsoft.Practices.Prism.Commands;
using Navigation.Silverlight;

namespace FU.Capstones.IMS.Web.Silverlight.ViewModels
{
    public class ExportMaterialOrderViewModel : ViewModelBase
    {
        public ExportMaterialOrderViewModel()
        {
            Model = new ExportMaterialOrderModel();
            ((ExportMaterialOrderModel)Model).GetWarehouseCollectionCompleted += DoGetWarehouseCollectionCompleted;
            ((ExportMaterialOrderModel)Model).InsertOrderCompleted += DoInsertOrderCompleted;
            ((ExportMaterialOrderModel)Model).GetEmployeeCollectionCompleted += DoGetEmployeeCollectionCompleted;
            ((ExportMaterialOrderModel)Model).GetContactCollectionCompleted += DoGetContactCollectionCompleted;
            //get collection material 
            ((ExportMaterialOrderModel)Model).GetMaterialCollectionCompleted += DoGetMaterialCollectionCompleted;
            EnterDateIsReadOnly = false;
            //visible add, save, reset button
            CanAdd = true;
            CanEditOrAdd = true;
        }

        #region ImplementEventCompleted
        void DoGetMaterialCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Material> e)
        {
            if (e.Error != null)
            {
                Message = e.Result.Message;
                MessageVisibility = Visibility.Visible;
            }
            else
            {
                Message = e.Result.Message;
                if (!e.Result.IsSuccessful)
                {
                    MessageVisibility = Visibility.Visible;
                }
                else
                {
                    MessageVisibility = Visibility.Collapsed;
                    SavedCollectionMaterial = new ObservableCollection<Material>(e.Result.Data);
                    for (int i = 0; i < CollectionMaterial.Count; i++)
                    {
                        for (int j = 0; j < SavedCollectionMaterial.Count; j++)
                        {
                            if (SavedCollectionMaterial[j].MaterialID == CollectionMaterial[i].MaterialID)
                            {
                                SavedCollectionMaterial.RemoveAt(j);
                            }
                        }
                    }

                }
            }
            ServiceCallCounter -= WebConstants.MagicNumer;
        }
        //void DoGetSingleOrderCompleted(object sender, SingleFeedbackCompletedEventArgs<Order> e)
        //{
        //    if (e.Error != null)
        //    {
        //        Message = e.Error.Message;
        //        MessageVisibility = Visibility.Visible;
        //    }
        //    else
        //    {
        //        Message = e.Result.Message;
        //        if (!e.Result.IsSuccessful)
        //        {
        //            MessageVisibility = Visibility.Visible;
        //        }
        //        else
        //        {

        //            CollectionMaterial = e.Result.Data.MaterialCollection;
        //            if (CollectionMaterial != null)
        //            {
        //                PagedCollectionMaterial = new PagedCollectionView(CollectionMaterial);
        //            }
        //            MaterialOrder = e.Result.Data;
        //            //map object in combobox
        //            if (MaterialOrder.EmployeeA.EmployeeID != 0 && EmployeeACollection != null)
        //            {
        //                MaterialOrder.EmployeeA =
        //               EmployeeACollection.First(
        //                   employee => employee.EmployeeID == MaterialOrder.EmployeeA.EmployeeID);
        //            }
        //            if (MaterialOrder.EmployeeB.EmployeeID != 0 && EmployeeBCollection != null)
        //            {
        //                MaterialOrder.EmployeeB =
        //               EmployeeBCollection.First(
        //                   employee => employee.EmployeeID == MaterialOrder.EmployeeB.EmployeeID);
        //            }
        //            if (MaterialOrder.Contact.ContactID != 0 && ContactCollection != null)
        //            {
        //                MaterialOrder.Contact =
        //               ContactCollection.First(
        //                   contact => contact.ContactID == MaterialOrder.Contact.ContactID);
        //            }
        //            if (MaterialOrder.MaterialCollection != null)
        //            {
        //                if (MaterialOrder.MaterialCollection[0].Warehouse.WarehouseID != 0 && WarehouseCollection != null)
        //                {
        //                    SelectedWarehouse =
        //                    WarehouseCollection.First(
        //                       warehouse => warehouse.WarehouseID == MaterialOrder.MaterialCollection[0].Warehouse.WarehouseID);
        //                }
        //            }

        //            //SavedCollectionMaterial = new ObservableCollection<Material>();
        //            if (e.Result.Data.IsImported == true)
        //            {
        //                IsImported = true;
        //                isExported = false;
        //            }
        //            else
        //            {
        //                IsImported = false;
        //                IsExported = true;
        //            }

        //            if (MaterialOrder.Contact.ContactID == 0)
        //            {
        //                IsInternal = true;
        //                IsExternal = false;
        //            }
        //            else
        //            {
        //                IsInternal = false;
        //                IsExternal = true;
        //            }
        //            //update orderdate
        //            EnterDateTime = MaterialOrder.OrderDate;
        //            EnterDateIsReadOnly = true;
        //            ServiceCallCounter += ((ExportMaterialOrderModel)Model).GetMaterialCollectionAsync(true);
        //        }
        //    }
        //    ServiceCallCounter -= WebConstants.MagicNumer;

        //}
        void DoInsertOrderCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (e.Error != null)
            {
                Message = e.Result.Message;
                MessageVisibility = Visibility.Visible;
                MessageBox.Show("Có lỗi không thể nhập được lô sản phẩm !");
            }
            else
            {
                Message = e.Result.Message;
                if (!e.Result.IsSuccessful)
                {
                    MessageVisibility = Visibility.Visible;
                    MessageBox.Show("Nhập đơn hàng không thành công");
                }
                else
                {
                    MessageVisibility = Visibility.Collapsed;
                    CollectionMaterial.Clear();
                    SavedCollectionMaterial.Clear();
                    MessageBox.Show("Nhập đơn hàng thành công");
                    //SavedMaterialOrder = new Order(){   Contact = MaterialOrder.Contact,
                    //                                    EmployeeA = MaterialOrder.EmployeeA,
                    //                                    EmployeeB = MaterialOrder.EmployeeB,
                    //                                    WarehouseID = MaterialOrder.WarehouseID,
                    //                                    MaterialCollection = MaterialOrder.MaterialCollection,
                    //                                    IsImported = MaterialOrder.IsImported,
                    //                                    OrderDate = MaterialOrder.OrderDate
                    //}; 

                }
            }
            ServiceCallCounter -= WebConstants.MagicNumer;

        }
        void DoGetWarehouseCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Warehouse> e)
        {
            if (e.Error != null)
            {
                Message = e.Result.Message;
                MessageVisibility = Visibility.Visible;
            }
            else
            {
                Message = e.Result.Message;
                if (!e.Result.IsSuccessful)
                {
                    MessageVisibility = Visibility.Visible;
                }
                else
                {
                    MessageVisibility = Visibility.Collapsed;
                    WarehouseCollection = new ObservableCollection<Warehouse>(e.Result.Data);
                    SelectedWarehouse = WarehouseCollection[0];

                }
            }
            ServiceCallCounter -= WebConstants.MagicNumer;
        }
        void DoGetContactCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Contact> e)
        {
            if (e.Error != null)
            {
                Message = e.Result.Message;
                MessageVisibility = Visibility.Visible;
            }
            else
            {
                Message = e.Result.Message;
                if (!e.Result.IsSuccessful)
                {
                    MessageVisibility = Visibility.Visible;
                }
                else
                {
                    MessageVisibility = Visibility.Collapsed;
                    ContactCollection = new ObservableCollection<Contact>(e.Result.Data);
                    MaterialOrder.Contact = ContactCollection[0];

                }
            }
            ServiceCallCounter -= WebConstants.MagicNumer;
        }
        void DoGetEmployeeCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Employee> e)
        {
            if (e.Error != null)
            {
                Message = e.Result.Message;
                MessageVisibility = Visibility.Visible;
            }
            else
            {
                Message = e.Result.Message;
                if (!e.Result.IsSuccessful)
                {
                    MessageVisibility = Visibility.Visible;
                }
                else
                {
                    MessageVisibility = Visibility.Collapsed;
                    EmployeeACollection = new ObservableCollection<Employee>(e.Result.Data);
                    EmployeeBCollection = new ObservableCollection<Employee>(e.Result.Data);
                    MaterialOrder.EmployeeA = EmployeeACollection[0];
                    MaterialOrder.EmployeeB = EmployeeBCollection[0];

                }
            }
            ServiceCallCounter -= WebConstants.MagicNumer;
        }

        #endregion

        #region Declare radCheck
        private DelegateCommand<object> radCheck;
        public DelegateCommand<object> RadCheck
        {
            get
            {
                if (radCheck == null)
                {
                    radCheck = new DelegateCommand<object>(DoRadCheck);
                }
                return radCheck;
            }
        }
        
        //Add new command use to and a new material loaf
        private DelegateCommand<object> addNewCommand;
        public DelegateCommand<object> AddNewCommand
        {
            get
            {
                if (addNewCommand == null)
                {
                    addNewCommand = new DelegateCommand<object>(DoAddNewCommand);
                }
                return addNewCommand;
            }
        }

        //Save command use to save collection material order to database
        private DelegateCommand<object> saveCommand;
        public DelegateCommand<object> SaveCommand
        {
            get
            {
                if (saveCommand == null)
                {
                    saveCommand = new DelegateCommand<object>(DoSaveCommand);
                }
                return saveCommand;
            }
        }

        //Back command use to turn back list order screeen
        private DelegateCommand<object> cancelCommand;
        public DelegateCommand<object> CancelCommand
        {
            get
            {
                if (cancelCommand == null)
                {
                    cancelCommand = new DelegateCommand<object>(DoBackCommand);
                }
                return cancelCommand;
            }
        }
        //Delete command use delete material from list material
        private DelegateCommand<object> deleteCommand;
        public DelegateCommand<object> DeleteCommand
        {
            get
            {
                if (deleteCommand == null)
                {
                    deleteCommand = new DelegateCommand<object>(DoDeleteCommand);
                }
                return deleteCommand;
            }
        }

        //Reset command use to reset list of material
        private DelegateCommand<object> resetCommand;
        public DelegateCommand<object> ResetCommand
        {
            get
            {
                if (resetCommand == null)
                {
                    resetCommand = new DelegateCommand<object>(DoResetCommand);
                }
                return resetCommand;
            }
        }

        #endregion

        #region Implement command
        private void DoRadCheck(object obj)
        {
            if (CollectionMaterial != null)
            {
                CollectionMaterial.Clear();
            }
            if (SavedCollectionMaterial != null)
            {
                SavedCollectionMaterial.Clear();
            }
        }
        private void DoAddNewCommand(object obj)
        {
            if (SelectedWarehouse != null)
            {
                
                    NavigationData sendNavigation = new NavigationData();
                    sendNavigation.Data = this;
                    sendNavigation.NavigationUri = WebConstants.NavigationPages.ExportMaterialOrder;
                    if (IsImported)
                    {
                        NavigationManager.NavigateTo(WebConstants.NavigationPages.MaterialImport, sendNavigation);

                    }
                    if (IsExported)
                    {
                        if (SelectedWarehouse.WarehouseID != 0)
                        {
                            NavigationManager.NavigateTo(WebConstants.NavigationPages.MaterialExport, sendNavigation);
                        }
                        else
                        {
                            MessageBox.Show("Bạn chưa chọn kho");
                        }
                    }
                    if (IsExported == false && IsImported == false)
                    {
                        MessageBox.Show("Bạn phải lựa chọn nhập hoặc xuất kho!");
                    }
               

            }



        }
        private void DoSaveCommand(object obj)
        {
            if (MaterialOrder.EmployeeA != null && (MaterialOrder.EmployeeB != null || MaterialOrder.Contact != null) && SelectedWarehouse.WarehouseID != 0)
            {
                if (PagedCollectionMaterial.Count != 0)
                {
                    MaterialOrder.WarehouseID = SelectedWarehouse.WarehouseID;
                    //check IsInternal and External to verify Contact and EmployeeB
                    //if IsInternal Contact = null
                    //if IsExternal EmployeeB = null
                    if (IsInternal)
                    {
                        MaterialOrder.Contact = null;
                    }
                    if (IsExternal)
                    {
                        MaterialOrder.EmployeeB = null;
                    }

                    DateTime? orderDate = DateTime.Now;

                    if (EnterDateTime != null)
                    {
                        string enterDateString = string.Format("{0:yyyy-MM-dd }", EnterDateTime) + string.Format("{0:HH:mm:ss}", DateTime.Now);
                        orderDate = DateTime.Parse(enterDateString);
                    }
                    else
                    {
                        EnterDateTime = DateTime.Now;
                    }
                    if (IsImported)
                    {
                        MaterialOrder.OrderCode = GetOrderCode(true, true);
                        MaterialOrder.OrderDate = orderDate;
                        MaterialOrder.MaterialCollection = CollectionMaterial;
                        MaterialOrder.IsImported = true;
                        //Order MyOrder = new Order()
                        //{
                        //    Contact = MaterialOrder.Contact,
                        //    EmployeeA = MaterialOrder.EmployeeA,
                        //    EmployeeB = MaterialOrder.EmployeeB,
                        //    WarehouseID = MaterialOrder.WarehouseID,
                        //    MaterialCollection = MaterialOrder.MaterialCollection,
                        //    IsImported = MaterialOrder.IsImported,
                        //    OrderDate = MaterialOrder.OrderDate
                        //}; 
                        //if (MyOrder  SavedMaterialOrder)
                        //{
                        //    InsertOrderConfirmationPopUp popup = new InsertOrderConfirmationPopUp();
                        //    popup.Show();
                        //    popup.Closed += (sender, e) =>
                        //    {

                        //        if (popup.DialogResult.HasValue && popup.DialogResult.Value)
                        //        {
                        //            ServiceCallCounter += ((ExportMaterialOrderModel)Model).InsertOrderAsync(MaterialOrder);
                        //        }
                        //    };
                        //}
                        //else
                        //{
                        //    ServiceCallCounter += ((ExportMaterialOrderModel)Model).InsertOrderAsync(MaterialOrder);
                        //}
                        ServiceCallCounter += ((ExportMaterialOrderModel)Model).InsertOrderAsync(MaterialOrder);

                    }
                    if (IsExported)
                    {
                        MaterialOrder.OrderCode = GetOrderCode(true, false);
                        MaterialOrder.OrderDate = orderDate;
                        MaterialOrder.MaterialCollection = CollectionMaterial;
                        MaterialOrder.IsImported = false;
                        //if (MaterialOrder == SavedMaterialOrder)
                        //{
                        //    InsertOrderConfirmationPopUp popup = new InsertOrderConfirmationPopUp();
                        //    popup.Show();
                        //    popup.Closed += (sender, e) =>
                        //    {

                        //        if (popup.DialogResult.HasValue && popup.DialogResult.Value)
                        //        {
                        //            ServiceCallCounter += ((ExportMaterialOrderModel)Model).InsertOrderAsync(MaterialOrder);
                        //        }
                        //    };
                        //}
                        //else
                        //{
                        //    ServiceCallCounter += ((ExportMaterialOrderModel)Model).InsertOrderAsync(MaterialOrder);
                        //}
                        ServiceCallCounter += ((ExportMaterialOrderModel)Model).InsertOrderAsync(MaterialOrder);
                    }
                    if (IsExported == false && IsImported == false)
                    {
                        MessageBox.Show("Bạn phải chọn hoặc là nhập hoặc là xuất kho!");
                    }

                }
                else
                {
                    MessageBox.Show("Bạn chưa chọn nguyên vật liệu nào cả!");
                }

            }
            else
            {
                MessageBox.Show("Bạn chưa điền đủ thông tin");
            }

        }
        private void DoBackCommand(object obj)
        {
            NavigationManager.NavigateTo(WebConstants.NavigationPages.MaterialOrderList);
        }
        private void DoResetCommand(object obj)
        {
            if (CollectionMaterial != null)
            {
                CollectionMaterial.Clear();
            }
            if (SavedCollectionMaterial != null)
            {
                SavedCollectionMaterial.Clear();
            }
            MaterialOrder.EmployeeA = EmployeeACollection[0];
            MaterialOrder.EmployeeB = EmployeeBCollection[0];
            MaterialOrder.Contact = ContactCollection[0];
        }
        private void DoDeleteCommand(object obj)
        {
            int deletedMaterialId = (int)obj;
            for (int i = 0; i < CollectionMaterial.Count; i++)
            {
                if (CollectionMaterial[i].MaterialID == deletedMaterialId)
                {
                    Material remove = CollectionMaterial[i];
                    CollectionMaterial.RemoveAt(i);
                    SavedCollectionMaterial.Insert(0, remove);

                }
            }

        }
        #endregion

        #region Save state

        private Warehouse selectedWarehouse;
        public Warehouse SelectedWarehouse
        {
            get { return selectedWarehouse; }
            set
            {
                if (!ReferenceEquals(selectedWarehouse, value))
                {
                    selectedWarehouse = value;
                    RaisePropertyChanged(() => SelectedWarehouse);
                }

            }
        }

        #endregion

        #region Biding to combobox

        private ObservableCollection<Warehouse> warehouseCollection;
        public ObservableCollection<Warehouse> WarehouseCollection
        {
            get { return warehouseCollection; }
            set
            {
                if (!ReferenceEquals(warehouseCollection, value))
                {
                    warehouseCollection = value;
                    RaisePropertyChanged(() => WarehouseCollection);
                }
            }
        }

        private ObservableCollection<Employee> employeeBCollection;
        public ObservableCollection<Employee> EmployeeBCollection
        {
            get { return employeeBCollection; }
            set
            {
                if (!ReferenceEquals(employeeBCollection, value))
                {
                    employeeBCollection = value;
                    RaisePropertyChanged(() => EmployeeBCollection);
                }
            }
        }

        private ObservableCollection<Employee> employeeACollection;
        public ObservableCollection<Employee> EmployeeACollection
        {
            get { return employeeACollection; }
            set
            {
                if (!ReferenceEquals(employeeACollection, value))
                {
                    employeeACollection = value;
                    RaisePropertyChanged(() => EmployeeACollection);
                }
            }
        }

        private ObservableCollection<Contact> contactCollection;
        public ObservableCollection<Contact> ContactCollection
        {
            get { return contactCollection; }
            set
            {
                if (!ReferenceEquals(contactCollection, value))
                {
                    contactCollection = value;
                    RaisePropertyChanged(() => ContactCollection);
                }
            }
        }
        #endregion

        #region Material loaf collection
        private PagedCollectionView materialLoafCollection;
        public PagedCollectionView MaterialLoafCollection
        {
            get { return materialLoafCollection; }
            set
            {
                if (!ReferenceEquals(materialLoafCollection, value))
                {
                    materialLoafCollection = value;
                    RaisePropertyChanged(() => MaterialLoafCollection);
                }
            }
        }
        #endregion

        #region MaterialOrder
        private Order materialOrder;
        public Order MaterialOrder
        {
            get { return materialOrder; }
            set
            {
                if (!ReferenceEquals(materialOrder, value))
                {
                    materialOrder = value;
                    RaisePropertyChanged(() => MaterialOrder);
                }
            }
        }

        #endregion
        #region SavedMaterialOrder
        private Order savedMaterialOrder;
        public Order SavedMaterialOrder
        {
            get { return savedMaterialOrder; }
            set
            {
                if (!ReferenceEquals(savedMaterialOrder, value))
                {
                    savedMaterialOrder = value;
                    RaisePropertyChanged(() => SavedMaterialOrder);
                }
            }
        }

        #endregion

        #region Collection Material

        private ObservableCollection<Material> collectionMaterial;
        public ObservableCollection<Material> CollectionMaterial
        {
            get { return collectionMaterial; }
            set
            {
                if (!ReferenceEquals(collectionMaterial, value))
                {
                    collectionMaterial = value;
                    RaisePropertyChanged(() => CollectionMaterial);
                }
            }
        }
        #endregion

        #region Saved collection material
        private ObservableCollection<Material> savedCollectionMaterial;
        public ObservableCollection<Material> SavedCollectionMaterial
        {
            get { return savedCollectionMaterial; }
            set
            {
                if (!ReferenceEquals(savedCollectionMaterial, value))
                {
                    savedCollectionMaterial = value;
                    RaisePropertyChanged(() => SavedCollectionMaterial);
                }
            }
        }

        private PagedCollectionView pagedCollectionMaterial;
        public PagedCollectionView PagedCollectionMaterial
        {
            get { return pagedCollectionMaterial; }
            set
            {
                if (!ReferenceEquals(pagedCollectionMaterial, value))
                {
                    pagedCollectionMaterial = value;
                    RaisePropertyChanged(() => PagedCollectionMaterial);
                }
            }
        }

        #endregion

        #region Implementation of INavigationAware

        public override void OnNavigate(object extraData)
        {
            var nd = (NavigationData)extraData;
            if (nd != null)
            {
                if (nd.NavigationUri.Equals(WebConstants.NavigationPages.MaterialImport) || nd.NavigationUri.Equals(WebConstants.NavigationPages.MaterialExport))
                {
                    if (nd.Data.GetType().Equals(typeof(ExportMaterialOrderViewModel)))
                    {
                        this.PagedCollectionMaterial = ((ExportMaterialOrderViewModel)nd.Data).PagedCollectionMaterial;
                        this.WarehouseCollection = ((ExportMaterialOrderViewModel)nd.Data).WarehouseCollection;
                        this.EmployeeACollection = ((ExportMaterialOrderViewModel)nd.Data).EmployeeACollection;
                        this.EmployeeBCollection = ((ExportMaterialOrderViewModel)nd.Data).EmployeeBCollection;
                        this.ContactCollection = ((ExportMaterialOrderViewModel)nd.Data).ContactCollection;
                        this.CollectionMaterial = ((ExportMaterialOrderViewModel)nd.Data).CollectionMaterial;
                        this.MaterialOrder = ((ExportMaterialOrderViewModel)nd.Data).MaterialOrder;
                        this.SelectedWarehouse = ((ExportMaterialOrderViewModel)nd.Data).SelectedWarehouse;

                        //biding saved state for radiobutton
                        this.IsExported = ((ExportMaterialOrderViewModel)nd.Data).IsExported;
                        this.IsImported = ((ExportMaterialOrderViewModel)nd.Data).IsImported;
                        this.IsInternal = ((ExportMaterialOrderViewModel)nd.Data).IsInternal;
                        this.IsExternal = ((ExportMaterialOrderViewModel)nd.Data).isExternal;
                        this.SavedCollectionMaterial = ((ExportMaterialOrderViewModel)nd.Data).SavedCollectionMaterial;
                        //get order date
                        this.EnterDateTime = ((ExportMaterialOrderViewModel)nd.Data).EnterDateTime;
                        this.savedMaterialOrder = ((ExportMaterialOrderViewModel) nd.Data).SavedMaterialOrder;

                    }
                }
                
            }
            else
            {
                ServiceCallCounter += ((ExportMaterialOrderModel)Model).GetWarehouseCollectionAsync(false);
                ServiceCallCounter += ((ExportMaterialOrderModel)Model).GetEmployeeCollectionAsync(false);
                ServiceCallCounter += ((ExportMaterialOrderModel)Model).GetContactCollectionAsync(false);
                CollectionMaterial = new ObservableCollection<Material>();
                PagedCollectionMaterial = new PagedCollectionView(CollectionMaterial);
                MaterialOrder = new Order();
                SelectedWarehouse = new Warehouse();
                SavedCollectionMaterial = new ObservableCollection<Material>();
                IsImported = true;
                IsInternal = true;

            }
        }

        public override void OnLeave()
        {
            //will be implemented in the sub classes
        }

        #endregion

        private DateTime? enterDateTime;
        public DateTime? EnterDateTime
        {
            get { return enterDateTime; }
            set
            {
                enterDateTime = value;
                RaisePropertyChanged(() => EnterDateTime);
            }
        }
        private bool isImported;
        public bool IsImported
        {
            get { return isImported; }
            set
            {
                isImported = value;
                RaisePropertyChanged(() => IsImported);

            }
        }
        private bool isExported;
        public bool IsExported
        {
            get { return isExported; }
            set
            {
                isExported = value;
                RaisePropertyChanged(() => IsExported);

            }
        }
        private bool isInternal;
        public bool IsInternal
        {
            get { return isInternal; }
            set
            {
                isInternal = value;
                RaisePropertyChanged(() => IsInternal);

            }
        }
        private bool isExternal;
        public bool IsExternal
        {
            get { return isExternal; }
            set
            {
                isExternal = value;
                RaisePropertyChanged(() => IsExternal);

            }
        }
        private bool enterDateIsReadOnly;
        public bool EnterDateIsReadOnly
        {
            get { return enterDateIsReadOnly; }
            set
            {
                enterDateIsReadOnly = value;
                RaisePropertyChanged(() => EnterDateIsReadOnly);

            }
        }


        #region GetOrderCode
        public string GetOrderCode(bool isMaterial, bool isImport)
        {
            string orderCode = "";
            if (isMaterial)
            {
                if (isImport)
                {
                    orderCode = orderCode + "MI";
                }
                if (!isImport)
                {
                    orderCode = orderCode + "ME";
                }
            }
            if (!isMaterial)
            {
                if (isImport)
                {
                    orderCode = orderCode + "PI";
                }
                if (!isImport)
                {
                    orderCode = orderCode + "PE";
                }
            }

            orderCode = orderCode + string.Format("{0:yyMMddHHmmss}", DateTime.Now);
            return orderCode;
        }

        #endregion

    }
}
